//是否登陆 可选true 或 false
var QJ_Login=false;
//桌面图标 请注意对应 images/ico.gif
var IcoText="|系统设置|文档目录|用户帐号|日志|照片|音乐盒|收藏夹|留言评论|心情|皮肤风格|装扮箱|博客应用|分类管理";

function $(obj){return document.getElementById(obj)}
function S(Divid,Ty){$(Divid).scrollTop=Ty}
function C(Divid,Css){$(Divid).className=Css}

//判断浏览器类型
function IsIe(){
var sVer=navigator.userAgent;
if(sVer.indexOf("MSIE")==-1){return false}else{return true}
}

//桌面图标
var OnIco_Id=null;
function OnIco(OnId,OnType){
switch (OnType){
	case "on":
		if(OnId==OnIco_Id)return;
		C(OnId,"IcoOn");
	break;
	case "out":
		if(OnId==OnIco_Id)return;
		C(OnId,"Ico");
	break;
	case "up":
		if(OnId==OnIco_Id)return;
		C(OnId,"IcoOn");
	break;
	case "down":
		if($(OnIco_Id))C(OnIco_Id,"Ico");
		OnIco_Id=OnId;
		C(OnId,"IcoDown");
	break;
	case "click":
		switch (OnId){
		case "A1": AddWin("A1","系统设置","Test.html",480,500,0,1);break;
		case "A2": AddWin("A2","文档目录","文档目录",780,480,2,0);break;
		case "A3": AddWin("A3","用户帐号","用户帐号",600,400,2,0);break;
		case "A4": AddWin("A4","日志","日志",500,200,2,0);break;
		case "A5": AddWin("A5","照片","照片",500,200,2,0);break;
		case "A6": AddWin("A6","音乐盒","音乐盒",500,200,2,0);break;
		case "A7": AddWin("A7","收藏夹","收藏夹",500,200,2,0);break;
		case "A8": AddWin("A8","留言评论","留言板",500,200,2,0);break;
		case "A9": AddWin("A9","心情","心情",500,200,2,0);break;
		case "A10": AddWin("A10","皮肤风格","皮肤风格",500,200,2,0);break;
		case "A11": AddWin("A11","装扮箱","装扮箱",500,200,2,0);break;
		case "A12": AddWin("A12","博客应用","博客应用",500,200,2,0);break;
		case "A13": AddWin("A13","分类管理","分类管理",500,200,2,0);break;
		}
	break;
	}
}

function InfoMenu(){
var IcoList="";
var ListNum=Math.floor((document.documentElement.clientHeight-70)/95);
var iNum=1,iList=1;
var iAll=IcoText.match(/\|/g).length;
for(var i=1;i<iAll+1;i++){
	if(iNum>ListNum){iNum=1;iList++}
	var T=20+95*(iNum-1);
	var L=100*iList-80;
	iNum++;
	var Cid="A"+i;
	IcoList+="<div id='"+Cid+"' style=\"top:"+T+"px;left:"+L+"px\" class='Ico' onmouseover=\"OnIco(this.id,'on')\" onmouseout=\"OnIco(this.id,'out')\" onmousedown=\"OnIco(this.id,'down');Move(event,this.id,0)\" onmouseup=\"OnIco(this.id,'up')\" ondblclick=\"OnIco(this.id,'click')\"><div class='IcoImg' style='background:url(js/plus/desktop/ico.gif) 0px -"+(50*i-50)+"px'></div><div class='IcoText'>"+IcoText.split("|")[i]+"</div></div>";
	}
$("QJ_WinIco").innerHTML=IcoList;
}

//禁止选择
document.onselectstart=function(e){return false}

//右键菜单
document.oncontextmenu=function(e){
var event=e||window.event;
var ele=e?event.target:event.srcElement;
var Cid=ele.id;
if(IsIe()){
	var YY=event.clientY;
	var XX=event.clientX;
	}else{
	var YY=e.clientY;
	var XX=e.clientX;
	}
$("QJ_Rmenu").style.display="";
var RHtml;
if(Cid.indexOf("_FootMenu")!="-1"||Cid.indexOf("_Move")!="-1"){
	Cid=Cid.split("_")[0];
	if($(Cid).style.display=="none"){
		RHtml="<a href='#' onclick=\"AddOpen('"+Cid+"');return false\">还原</a>";
		}else{
		RHtml="<a href='#' onclick=\"AddOpen('"+Cid+"');return false\">最小化</a>";
		}
	RHtml+="<a href='#' onclick=\"AddClose('"+Cid+"');return false\">关闭窗口</a>";
	}else{
		if(!QJ_Login){
		RHtml="<a href='#' onclick='LoginNow(0);return false'>登陆系统</a><a href='#' onclick='window.close();return false'>关闭</a>"
		}else{
		RHtml="<a href='#' onclick=\"InfoMenu();return false\">自动排列</a><a href='#' onclick=\"QJ_Refresh();return false\">刷新</a><a href='/' target=_blank>站点首页</a><a href='#' onclick=\"E('待开发中...','');return false\">属性</a>";
		}
	}
RHtml+="<a href='#' onclick=\"E('lovebugs<br>BLOG：<a target=_blank href=http://blog.pfan.cn/lovebugs>http://blog.pfan.cn/lovebugs</a>','');return false\">关于作者</a>";
$("QJ_Rmenu").innerHTML=RHtml;
var H=document.documentElement.clientWidth-124;
var H2=document.documentElement.clientHeight-$("QJ_Rmenu").scrollHeight-2;
if(XX>H)XX=H;
if(YY>H2)YY=H2;
$("QJ_Rmenu").style.top=YY+"px";
$("QJ_Rmenu").style.left=XX+"px";
return false
}

//改变窗口显示
function ChangeWin(){
var W=document.documentElement.clientWidth-273;
$("QJ_WinFinfo").style.width=W+"px";
ChangeWList("");
}
var CWlistTimer;
function ChangeWList(Ctype){
if(Ctype==""){
	var N=$("QJ_WinList").childNodes.length;
	$("QJ_WinList").style.width=101*N+"px";
	$("QJ_WinFinfo").scrollLeft=$("QJ_WinFinfo").scrollWidth;
	if($("QJ_WinFinfo").clientWidth<$("QJ_WinFinfo").scrollWidth){$("QJ_FScro").style.display=""}else{$("QJ_FScro").style.display="none"}
	}
if(Ctype=="left"){
	$("QJ_WinFinfo").scrollLeft=$("QJ_WinFinfo").scrollLeft-5;
	CWlistTimer=window.setTimeout("ChangeWList('left')",10);
	}
if(Ctype=="right"){
	$("QJ_WinFinfo").scrollLeft=$("QJ_WinFinfo").scrollLeft+5;
	CWlistTimer=window.setTimeout("ChangeWList('right')",10)
	}
if(Ctype=="out"){clearTimeout(CWlistTimer)}
}

//时间日期
function InfoTime(){
var MyDate=new Date();
var Text=MyDate.getMonth()+"月"+MyDate.getDate()+"日 "+MyDate.toLocaleTimeString()
$('QJ_Time').innerHTML=Text;
}
//重新载入
function QJ_Refresh(){
InfoMenu();
$("QJ_WinList").innerHTML="";
$("QJ_WinPage").innerHTML="";
}
//移动窗口
var MoveObj=null,MoveType,MoveX,MoveY,MoveW,MoveH;
function Move(event,Obj,MoveT){
if($(MoveObj))return;
var evt=event?event:(window.event?window.event:null);
if(IsIe()){
	var YY=event.clientY;
	var XX=event.clientX;
	}else{
	var YY=evt.clientY;
	var XX=evt.clientX;
	}
MoveObj=Obj;MoveType=MoveT;
if(MoveT==0){MoveX=parseInt($(MoveObj).style.left)-XX;MoveY=parseInt($(MoveObj).style.top)-YY}
else if(MoveT==1){
	MoveX=XX;MoveY=YY
	MoveW=$(MoveObj).clientWidth;
	MoveH=$(MoveObj).clientHeight;
	$("QJ_None").style.display="";
	$("QJ_None").style.top=$(MoveObj).style.top;
	$("QJ_None").style.left=$(MoveObj).style.left;
	$("QJ_None").style.width=$(MoveObj).style.width;
	$("QJ_None").style.height=$(MoveObj).style.height;
	}
}
document.onmousemove=function(e){
if(!$(MoveObj))return;
if(IsIe()){
	var YY=event.clientY;
	var XX=event.clientX;
	}else{
	var YY=e.clientY;
	var XX=e.clientX;
	}
if(MoveType==0){
	var _xx=MoveX+XX;var _yy=MoveY+YY;
	var Mx=document.documentElement.clientWidth-$(MoveObj).clientWidth;
	var My=document.documentElement.clientHeight-30-$(MoveObj).clientHeight;
	if(_xx>Mx)_xx=Mx;
	if(_yy>My)_yy=My;
	if(_xx<0)_xx=0;
	if(_yy<0) _yy=0;
	$(MoveObj).style.left=_xx+"px";
	$(MoveObj).style.top=_yy+"px";
	}
else if(MoveType==1){
	var W=XX-MoveX+MoveW;
	var H=YY-MoveY+MoveH;
	if(W<110)W=110;
	if(H<40)H=40;
	$("QJ_None").style.width=W+"px";
	$("QJ_None").style.height=H+"px";
	}
}
//鼠标弹起事件
document.onmouseup=function(e){
if($(MoveObj)&&$("QJ_None").style.display!="none"){
	$(MoveObj).style.width=$("QJ_None").style.width;
	$(MoveObj).style.height=$("QJ_None").style.height;
	$(MoveObj+"_Con").style.width=($("QJ_None").clientWidth-10)+"px";
	$(MoveObj+"_Con").style.height=($("QJ_None").clientHeight-33)+"px";
	}
MoveObj=null;
$("QJ_None").style.display="none";

var event=e||window.event;
var ele=e?event.target:event.srcElement;
var Cid=ele.id;
if(Cid=="QJ_WinIco"&&$(OnIco_Id)){C(OnIco_Id,"Ico");OnIco_Id=null}
$("QJ_Rmenu").style.display="none";
if(Cid=="KsMenu"){KSopen()}else{$("QJ_KsMenu").style.display="none"}
//$("QJ_Time").innerHTML=Cid
}

//创建新窗口
var AddTopZindex=1,AddTopOn=null;
function AddWin(Aid,Atitle,Aurl,Aw,Ah,Atype,Abut){
	var Cid="New"+Aid;
	if($(Cid)){
		if($(Cid).style.display=="none"){AddSee(Cid,"")}else{AddTop(Cid)}
		return;
		}
	var Acon="";
	if(Atype==1){Acon="<IFRAME style='width:100%;height:100%' src='"+Aurl+"' frameBorder=0></IFRAME>";Aurl=""}
	else if(Atype==2){Acon=Aurl;Aurl=""}
	var oDiv=document.createElement("div");
	oDiv.id=Cid;
	oDiv.className="WinCss";
	oDiv.style.zIndex=AddTopZindex;
	oDiv.style.width=(Aw+10)+"px";
	oDiv.style.height=(Ah+33)+"px";
	var X=(document.documentElement.clientWidth-Aw-10)/2;
	if(X<0)X=0;
	oDiv.style.left=X+"px";
	//oDiv.style.top=document.documentElement.clientHeight-30+"px";
	oDiv.style.top=((document.documentElement.clientHeight-Ah-64)/2+10)+"px";
	var CloseBut="<div id='"+Cid+"C3' style='width:43px' onmouseover=\"S(this.id,17)\" onmouseout=\"S(this.id,0)\" onmousedown=\"S(this.id,34)\" onclick=\"S(this.id,17);AddClose('"+Cid+"')\"><img src='js/plus/desktop/b.gif' style='margin-left:-51px'></div>";
	if(Abut==0){
	var DblClick="ondblclick=\"AddBig('"+Cid+"',"+Aw+","+Ah+")\""
	CloseBut+="<div id='"+Cid+"C2' style='width:26px' onmouseover=\"S(this.id,17)\" onmouseout=\"S(this.id,0)\" onmousedown=\"S(this.id,34)\" onclick=\"S(this.id,17);AddBig('"+Cid+"',"+Aw+","+Ah+")\"><img src='js/plus/desktop/b.gif' style='margin-left:-25px'></div>";
	}else{
	DblClick=" "
	}
	CloseBut+="<div id='"+Cid+"C1' style='width:25px' onmouseover=\"S(this.id,17)\" onmouseout=\"S(this.id,0)\" onmousedown=\"S(this.id,34)\" onclick=\"S(this.id,17);$('"+Cid+"').style.display='none'\"><img src='js/plus/desktop/b.gif'></div>";
	var Html="<table class='WinTab' cellpadding='0' cellspacing='0'>"+
		 "<tr><td class='Win1'></td><td class='Win2'>&nbsp;"+Atitle+"</td><td class='Win3'></td></tr>"+
		 "<tr><td class='Win4'></td><td class='Win5'><div id='"+Cid+"_Con' class='WinCon' style='width:"+Aw+"px;height:"+Ah+"px'>"+Acon+"</div></td><td class='Win6'></td></tr>"+
		 "<tr><td class='Win7'></td><td class='Win8'>&nbsp;</td><td class='Win9'></td></tr></table><div class='WinClose'>"+CloseBut+"</div><div id='"+Cid+"_Move' class='WinMove'"+DblClick+" onmousedown=\"AddTop('"+Cid+"');Move(event,'"+Cid+"',0)\"></div><div class='WinIframe'><iframe style='width:100%;height:100%' src='about:blank' frameBorder=0 scrolling=no></iframe></div>";
	if(Abut==0)Html+="<div class='WinResize' onmousedown=\"Move(event,'"+Cid+"',1)\"></div>";
	oDiv.innerHTML=Html;
	$("QJ_WinPage").appendChild(oDiv);
	AddTopOn=Cid;	

	var oDiv2=document.createElement("div");
	var CidF=Cid+"_Foot";
	oDiv2.id=CidF
	oDiv2.className="WinCss_Foot";
	oDiv2.innerHTML="<div id='"+CidF+"But' class='WinCss_F1'><img src='js/plus/desktop/b.gif'></div><div id='"+CidF+"Menu' class='WinCss_F2' onmouseover=\"S('"+CidF+"But',24)\" onmouseout=\"S('"+CidF+"But',0)\" onmousedown=\"S('"+CidF+"But',48);this.style.lineHeight='230%'\" onclick=\"S('"+CidF+"But',24);AddOpen('"+Cid+"');this.style.lineHeight='210%'\">"+Atitle+"</div>";
	$("QJ_WinList").appendChild(oDiv2);
	AddSee(Cid,Aurl);
	ChangeWList("");
}
var AddTimer;
function AddSee(Cid,Aurl){
if(!$(Cid))return;
if($(Cid).style.display=="none"){
	$(Cid).style.top=((document.documentElement.clientHeight-$(Cid).clientHeight-30)/2+10)+"px";
	$(Cid).style.display="";
	AddTop(Cid);
	}
var Y=(document.documentElement.clientHeight-$(Cid).clientHeight-30)/2;
if(Y<0)Y=0;
var T=parseInt($(Cid).style.top);
if(T>Y){
	var N;
	if(T-Y>120){N=120}else if(T-Y>60){N=60}else if(T-Y>30){N=20}else if(T-Y>20){N=10}else{N=1}
	$(Cid).style.top=(T-N)+"px";
	AddTimer=window.setTimeout("AddSee('"+Cid+"','"+Aurl+"')",20)
	}else{
	if(Aurl!=""){AjaxGet(Aurl,Cid+"_Con",1,1)}
	}
}
//关闭
function AddClose(Cid){
if(!QJ_Login){E("请先登陆系统!","");return}
$("QJ_WinList").removeChild($(Cid+"_Foot"));
$("QJ_WinPage").removeChild($(Cid));
ChangeWList("");
}
//隐藏与显示
function AddOpen(Cid){
clearTimeout(AddTimer);
if($(Cid).style.display=="none"){AddSee(Cid,"")}else{$(Cid).style.display="none"}
}
//最大化
function AddBig(Cid,Aw,Ah){
if($(Cid).style.display=="none"){$(Cid).style.display=""}
var S=$(Cid+"C2").scrollLeft;
var W=document.documentElement.clientWidth;
var H=document.documentElement.clientHeight;
if(S==0){
	$(Cid+"C2").scrollLeft=94;
	$(Cid).style.left="0px";
	$(Cid).style.top="0px";
	$(Cid).style.width=W+"px";
	$(Cid).style.height=H-30+"px";
	$(Cid+"_Con").style.width=(W-10)+"px";
	$(Cid+"_Con").style.height=(H-64)+"px";
	}else{
	$(Cid+"C2").scrollLeft=0;
	$(Cid).style.width=(Aw+10)+"px";
	$(Cid).style.height=(Ah+33)+"px";
	$(Cid+"_Con").style.width=Aw+"px";
	$(Cid+"_Con").style.height=Ah+"px";
	var X=(document.documentElement.clientWidth-Aw-10)/2;if(X<0)X=0;
	var Y=(document.documentElement.clientHeight-Ah-64)/2;if(Y<0)Y=0;
	$(Cid).style.left=X+"px";
	$(Cid).style.top=Y+"px";
	}
}
//窗口置顶
function AddTop(Cid){
if(Cid==AddTopOn)return;
AddTopZindex++
$(Cid).style.zIndex=AddTopZindex;
AddTopOn=Cid;
}

//开始菜单
function KSopen(){
if(!QJ_Login){E("请先登陆系统!","");return}
if($("QJ_KsMenu").style.display=="none"){
	$("QJ_KsMenu").style.display="";		
	}else{
	$("QJ_KsMenu").style.display="none";
	}
}
//创建提示窗口
function E(Emsg,Etype){
$("QJ_Msg").style.display="";
$("QJ_MsgText").innerHTML=Emsg;
if(Etype==""){var Ehtml="<div id='EmsgBut1' style='margin-left:42px' class='ButDiv' style='margin:auto' onmouseover=\"S(this.id,24)\" onmouseout=\"S(this.id,0)\" onmousedown=\"S(this.id,48)\" onclick=\"S(this.id,24);G('')\"><img src='js/plus/desktop/b.gif' class='But' style='margin-left:-71px'></div>"}
else{var Ehtml="<div id='EmsgBut1' class='ButDiv' style='float:left' onmouseover=\"S(this.id,24)\" onmouseout=\"S(this.id,0)\" onmousedown=\"S(this.id,48)\" onclick=\"S(this.id,24);G('"+Etype+"')\"><img src='js/plus/desktop/b.gif' class='But' style='margin-left:-71px'></div><div style='float:right' id='EmsgBut2' class='ButDiv' style='margin:auto' onmouseover=\"S(this.id,24)\" onmouseout=\"S(this.id,0)\" onmousedown=\"S(this.id,48)\" onclick=\"S(this.id,24);G('')\"><img src='js/plus/desktop/b.gif' class='But' style='margin-left:-142px'></div>"}
$("QJ_MsgBut").innerHTML=Ehtml;
//alert($("QJ_MsgBut").innerHTML);
}
function G(GText){
$("QJ_Msg").style.display="none";
if(GText!=""){
	GText=GText.replace(/\|/g,"'");
	GText=GText.replace(/\$/g,"\"");
	var obj=eval(GText);
	}
}
//按键事件
document.onkeydown=function(e){
var e=window.event?window.event:e;
var srcEle=e.srcElement?e.srcElement:e.target;
var Key=e.keyCode;
if(Key==13&&$("QJ_Login")){LoginNow(1)}
}
//登陆事件
function LoginNow(LoginNum){
if(LoginNum==0){AddWin("Login","登陆系统","admin_Login.html",380,160,1,1)}
if(LoginNum==1){
	QJ_Login=true;InfoMenu();
	if($("NewLogin")) AddClose("NewLogin");
	}
}
//网页加载事件
window.onload = function(){
Loading("over");
ChangeWin();
setInterval("InfoTime()",1000);
if(!QJ_Login){LoginNow(1)}else{LoginNow(1)}
}
